package com.xxl.javawork;

/**
 *矩形类，储藏宽高属性，实现矩形周长和面积的计算
 * @author xiaxinlin
 * @version 1.0
 * @since jdk1.8
 * @date 2021/1/9 22:41
 */
public class RectangleCal {

    //高
    private double height;
    //宽
    private double width;

    /**
     * 矩形构造器，并设置高和宽
     *
     * @param height 矩形的高
     * @param width 矩形的宽
     * @author xiaxinlin
     * @creed: Talk is cheap,show me the code
     * @date 2021/1/9
     */
    public RectangleCal(double height, double width) {
        this.height = height;
        this.width = width;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    /**
     * 计算矩形面积
     *
     * @return double 矩形面积，保留小数点后两位
     * @author xiaxinlin
     * @creed: Talk is cheap,show me the code
     * @date 2021/1/9
     */
    public double getArea(){
        return Math.round(height*width*100)/100.0;
    }

    /**
     * 计算矩形周长
     *
     * @return double 矩形周长，保留小数点后两位
     * @author xiaxinlin
     * @creed: Talk is cheap,show me the code
     * @date 2021/1/9
     */
    public double getGirth(){
        return Math.round(2*(height+width)*100)/100.0;
    }
}
